package com.hisan.freeride.home.activity;

import android.view.View;


import com.hisan.freeride.R;
import com.hisan.freeride.common.base.AppConfig;
import com.hisan.freeride.common.base.BaseActivity;
import com.hisan.freeride.common.callback.DialogCallback;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.common.utils.utils.TokenUtils;
import com.hisan.freeride.databinding.NewMeBinding;
import com.hisan.freeride.home.model.News;
import com.hisan.freeride.home.model.WoMessage;
import com.lzy.okgo.OkGo;

import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.List;

import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 创建时间 : 2017/6/8
 * 创建人：yangyingqi
 * 公司：嘉善和盛网络有限公司
 * 备注：消息首页
 */
public class NewsActivity extends BaseActivity<NewMeBinding> {


    @Override
    protected int getLayoutId() {
        return R.layout.new_me;
    }


    @Override
    protected void initView() {
        //爱心消息
        mBinding.selectLove.setOnClickListener(v -> startActivityForResult(WoMessageActivity.class,0,null,true));
    }

    @Override
    protected void initEvent() {
        mBinding.topBack.setOnClickListener(v -> finishActivity(true));
    }

    @Override
    protected void loadData(boolean isRefresh) {
        OkGo.<List<WoMessage>>get(AppConfig.MyMessage)
                .tag(this)

                .execute(new DialogCallback<List<WoMessage>>(this) {
                    @Override
                    public void onSuccess(com.lzy.okgo.model.Response<List<WoMessage>> response) {
                        super.onSuccess(response);
                        if (!CollectionUtils.isNullOrEmpty(response)){
                            if (isOk(response)){
                                if (!CollectionUtils.isNullOrEmpty(response.body())){
                                    mBinding.content.setText(response.body().get(0).getTitle());
                                    mBinding.newdata.setText(response.body().get(0).getCreate_time());
                                }else{
                                    mBinding.content.setText("暂无消息");
                                }
                            }else {
                                showErrorView(response.code());
                            }
                        }
                    }

                    @Override
                    public void onError(com.lzy.okgo.model.Response<List<WoMessage>> response) {
                        super.onError(response);
                        showErrorView(response.code());
                    }
                });
    }


}
